<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>网页存储</title>
</head>
<body>
<textarea rows="5" cols="30" id="txt-data"></textarea>
<input type="button" value="设置数据" id="set-data">
<input type="button" value="获取数据" id="get-data">
<script>
    (function(){
        var txtValue = document.querySelector("#txt-data");
        console.log(txtValue.value);
        //设置数据
        document.querySelector("#set-data").addEventListener("click",function (e) {
            //判断是否支持存储
            if(window.sessionStorage){
                sessionStorage.setItem("key",txtValue.value);
            }else{
                console.log("还在用渣渣IE吗？升级吧。。。")
            }
        })

        //获取数据
        document.querySelector("#get-data").addEventListener("click",function (e) {
            //判断是否支持存储
            if(window.sessionStorage){
                txtValue.value = sessionStorage.getItem("key");
            }else{
                console.log("还在用渣渣IE吗？升级吧。。。")
            }
        })
    })()
</script>
</body>
</html>